package com.weitu.majorHazard.statisticsAnalysis.controller;

import com.weitu.base.controller.BaseController;
import com.weitu.majorHazard.statisticsAnalysis.entity.ActivityRecordStatisticsAnalysis;
import com.weitu.majorHazard.statisticsAnalysis.entity.DeviceLevelStatisticsAnalysis;
import com.weitu.majorHazard.statisticsAnalysis.service.StatisticsAnalysisService;
import com.weitu.util.AjaxResult;
import com.weitu.util.TableTreeNodeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by smp on 2017/4/24.
 */
@Controller
@RequestMapping(value = "majorHazard/statisticsAnalysis")
public class StatisticsAnalysisController extends BaseController {
    private static final String MODULE_BATH_PATH=BASE_JSP_PATH+"majorHazard/statisticsAnalysis";

    private final StatisticsAnalysisService statisticsAnalysisService;

    @Autowired
    public StatisticsAnalysisController(StatisticsAnalysisService statisticsAnalysisService){
        this.statisticsAnalysisService=statisticsAnalysisService;
    }

    /**
     * 安装置级别统计
     * @return
     */
    @RequestMapping(value = "/deviceLevelStatistics",method = RequestMethod.GET)
    public String deviceLevelStatistics(){
        return MODULE_BATH_PATH+"/deviceLevelStatistics";
    }

    /**
     * 统计
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/deviceLevelStatistics",method = RequestMethod.POST)
    public List<Map<String,Object>> deviceLevelStatisticsAjax(HttpServletRequest request){
        Map<String,Object> paramMap=new HashMap<String,Object>();
        putParametersIntoMap(paramMap);
        List<Map<String,Object>> maps=this.statisticsAnalysisService.analysisByLevel(paramMap);
        List<Map<String,Object>> mapList= TableTreeNodeUtil.getFatherNode(maps);
        return mapList;
    }

    /**
     * 按活动记录统计
     * @return
     */
    @RequestMapping(value = "/activityRecordStatistics",method = RequestMethod.GET)
    public String activityRecordStatistics(){
        return MODULE_BATH_PATH+"/activityRecordStatistics";
    }

    /**
     * 分析统计
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/activityRecordStatistics",method = RequestMethod.POST)
    public List<ActivityRecordStatisticsAnalysis> activityRecordStatisticsAjax(){
        Map<String,Object> paramMap=new HashMap<String,Object>();
        putParametersIntoMap(paramMap);
        ActivityRecordStatisticsAnalysis activityRecordStatisticsAnalysis=this.statisticsAnalysisService.analysisByActivityRecord(paramMap);
        List<ActivityRecordStatisticsAnalysis> analysisList=new ArrayList<ActivityRecordStatisticsAnalysis>();
        analysisList.add(activityRecordStatisticsAnalysis);
        return analysisList;
    }
    /**
     * 查询条件
     * @return
     */
    @RequestMapping(value = "/select",method = RequestMethod.GET)
    public String select(){
        return MODULE_BATH_PATH+"/select";
    }

    /**
     * 检查用户名
     * @param name
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/checkUserName",method = RequestMethod.POST)
    public AjaxResult checkUser(String name){
        int count=this.statisticsAnalysisService.checkUserName(name);

        if(count>0){
            return AjaxResult.success("用户名存在");
        }else {
            return AjaxResult.fail("用户名不存在");
        }
    }

    /**
     * 按综合信息统计
     * @return
     */
    @RequestMapping(value = "/integratedInformationStatistics",method = RequestMethod.GET)
    public String integratedInformationStatistics(){
        return MODULE_BATH_PATH+"/integratedInformationStatistics";
    }
}
